import { Controller, Get, Post, Query, ValidationPipe, Body } from '@nestjs/common';
import { CreateCommentDto, QueryCommentDto } from "src/Dto/Comment.Dto";
import { CommentService } from "src/service/Comment.Service";

@Controller('/comment')
export class CommentController{
    constructor(
        private commentService:CommentService
    ){}

    @Get('/getRoot')
    getFindRoot(){
       return this.commentService.findTree()
    }

    @Get('/page')
    FindCommentAndPaging(@Query(
        new ValidationPipe({
            transform:true,
            forbidNonWhitelisted:true,
            validationError: { target: false },
        })
    )query: QueryCommentDto){
        return this.commentService.FindCommentAndPaging(query)
    }

    //给文章添加评论
    @Post('/addComment')
    addComment(
        @Body(
            new ValidationPipe({
                forbidNonWhitelisted:true,
                transform:true,
                validationError:{target:true}
            })
        )
        option:CreateCommentDto
    ){
        return this.commentService.create(option)
    }

   
}